/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author user
 */
public class Room implements Comparable<Room> {

    public int id;
    public String name;
    public int categoryId;
    public int ownerId;
    public boolean persistance;
    public Users joinUsers = new Users();
    public Users banUsers = new Users();

    public Room(int id, String name, int category_id, int owner_id, boolean persistance) {
        this.id = id;
        this.name = name;
        this.categoryId = category_id;
        this.ownerId = owner_id;
        this.persistance = persistance;
    }

    public int compareTo(Room o) {
        return o.id - this.id;
    }

    public boolean addJoinUser(User user) {
        if (banUsers.find(user.id) == null) {
            if (!joinUsers.contains(user)) {
                joinUsers.add(user);
                if (joinUsers.size() == 1) {
                    ownerId = user.id;
                }
                return true;
            }
        }

        return false;
    }

    public void removeJoinUser(int userId) {
        User user = joinUsers.find(userId);
        if (user != null) {
            joinUsers.remove(user);
        }
    }

    public void addBanUsers(User user) {
        if (!banUsers.contains(user)) {
            banUsers.add(user);

            // Kick if online
            User join = joinUsers.find(user.id);
            if (join != null) {
                join.kick = true;
            }
        }
    }

    public void removeBanUsers(String username) {
        User user = banUsers.find(username);
        if (user != null) {
            banUsers.remove(user);
        }
    }

    public void markKickToUser(String username) {
        User user = banUsers.find(username);
        user.kick = true;
    }
}
